#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    myButton = new QPushButton(this);
    myButton->setText("按钮1");
    myButton->move(200, 200);

    connect(myButton, &QPushButton::clicked, this, &Widget::handleClick); // 给点击信号绑定槽函数

    connect(this, &Widget::mySignals, this, &Widget::handleSignal); // 给自定义信号绑定槽函数

    myButton2 = new QPushButton(this);
    myButton2->setText("更改按钮1槽函数");
    myButton2->move(300, 300);
    connect(myButton2, &QPushButton::clicked, this, &Widget::modifyHandler);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::handleClick()
{
    emit mySignals("hello");
    qDebug() << "hello";
}

void Widget::handleClick2()
{
    emit mySignals("jiuqi");
    qDebug() << "jiuqi";
}

void Widget::handleSignal(QString text)
{
    setWindowTitle(text);
}

void Widget::modifyHandler()
{
    disconnect(myButton, &QPushButton::clicked, this, &Widget::handleClick); // 解绑
    connect(myButton, &QPushButton::clicked, this, &Widget::handleClick2);
}



